import {
  getDicts
} from '@/api/dict.js'

export default {
  data() {
    return {
      dictType: {}
    }
  },
  methods: {
    /**
     * 获取字典数据
     * @param {Object} dictType
     * @param {Object} query
     */
    getDict(dictType, query = {}) {
      const sendObj = {
        label: dictType,
      }
      if (Object.keys(query).length) {
        sendObj['query'] = query
      }
      getDicts(sendObj).then(res => {
        const dictData = []
        res.data.forEach(dictItem => {
          let elTagType = ''
          let elTagClass = ''
          if (dictItem.memo && dictItem.memo.trim() && dictItem.memo.indexOf('|') !== -1) {
            elTagType = dictItem.memo.split('|')[0]
            elTagClass = dictItem.memo.split('|')[1]
          }
          dictData.push({
            label: dictItem.name,
            text: dictItem.name,
            name: dictItem.name,
            value: dictItem.value,
            disable: false,
            elTagType,
            elTagClass,
          })
        })
        this.$set(this.dictType, dictType, dictData)
      })
    }
  }
}